package com.sky.controller.admin;

import com.sky.result.Result;
import com.sky.service.impl.ReportServiceImpl;
import com.sky.vo.SalesTop10ReportVO;
import com.sky.vo.TurnoverReportVO;
import com.sky.vo.UserReportVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import net.bytebuddy.asm.Advice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

@RestController
@Slf4j
@Api(tags = "数据统计接口")
@RequestMapping("/admin/report/")
public class ReportController {
    @Autowired
    private ReportServiceImpl reportService;
    @ApiOperation("营业额统计")
    @GetMapping("/turnoverStatistics")
    public Result getTurnoverStatistics(String begin, String end) throws Exception
    {
        LocalDate Begin = LocalDate.parse(begin.trim());
        LocalDate End = LocalDate.parse(end.trim());
        TurnoverReportVO result = reportService.getTurnoverStatistics(Begin,End);
        return Result.success(result);
    }

    @ApiOperation("用户数据统计")
    @GetMapping("/userStatistics")
    public Result getuserStatistics(String begin, String end){
        LocalDate Begin = LocalDate.parse(begin.trim());
        LocalDate End = LocalDate.parse(end.trim());
        UserReportVO result = reportService.getuserStatistics(Begin,End);
        return Result.success(result);
    }

    @ApiOperation("获取指定时间段内的Top10商品及其销量")
    @GetMapping("/top10")
    public Result gettop10(String begin, String end){
        LocalDate Begin = LocalDate.parse(begin.trim());
        LocalDate End = LocalDate.parse(end.trim());
        SalesTop10ReportVO result = reportService.getTop10(Begin,End);
        return Result.success(result);
    }
}
